//
//  HelpContractCell.m
//  Yihubang
//
//  Created by xmy on 2016/12/9.
//  Copyright © 2016年 xmy. All rights reserved.
//

#import "HelpContractCell.h"
@implementation HelpContractCell

- (void)awakeFromNib {
    [super awakeFromNib];
    NSMutableArray *imgArray = [NSMutableArray array];
    for (int i=1; i<4; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"语音条%d.png",i]];
        [imgArray addObject:image];
    }
    //把存有UIImage的数组赋给动画图片数组
    self.hearRecorder.animationImages = imgArray;
    self.hearRecorder.animationDuration = 1;
    self.hearRecorder.animationRepeatCount = 30;
    self.contractHe.cornerRadius =3.f;
    self.contractHe.masksToBounds =YES;
//    self.hearRecorder.cornerRadius =3.f;
//    self.hearRecorder.masksToBounds =YES;
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(void)showSbContract:(NSDictionary *) contractInfo{
    self.contractView.hidden = NO;
    self.recorderView.hidden = YES;
    self.name_label.text =contractInfo[@"name"];
    @weakify(self)
    [[self.contractHe rac_signalForControlEvents:UIControlEventTouchUpInside]
     subscribeNext:^(id x) {
         @strongify(self)
         if(self.contractCommend){
             [self.contractCommend execute:contractInfo[@"phone"]];
         }
     }];
}
-(void)showRecoder:(NSDictionary *) contractInfo AndIndex:(NSInteger)index{
    self.recorderView.hidden = NO;
    self.contractView.hidden = YES;
    self.time_label.text = [self timeString:contractInfo[@"add_time"]];
    NSLog(@"%@",contractInfo);
    if([contractInfo[@"listened"] isEqualToString:@"1"]){
        self.mark.hidden = YES;
    }else{
        self.mark.hidden = NO;
    }
    @weakify(self)
    [self.hearRecorder setTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
        @strongify(self)
        [self.preparePlayCommend execute:@[contractInfo,[NSNumber numberWithInteger:index]]];
        self.mark.hidden = YES;
    }];
}
-(NSString *)timeString:(NSString *)timeStr{
    NSTimeInterval time=[timeStr doubleValue];
    
    NSDate*detaildate=[NSDate dateWithTimeIntervalSince1970:time];
    NSDateFormatter*dateFormatter = [[NSDateFormatter alloc]init];
    [dateFormatter setDateFormat:@"HH:mm"];
//    [string substringWithRange:range]
    NSString *currentDateStr = [dateFormatter stringFromDate:detaildate];
//    NSString *time_label = [currentDateStr substringWithRange:NSMakeRange([currentDateStr length] - 8, 8)];
    return currentDateStr;
}

@end
